package com.pc.admin.controller;


import com.pc.admin.service.MinioService;
import com.pc.admin.util.CommonResult;
import com.pc.admin.util.MinioUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Api(tags = "文件操作接口")
@RestController
@RequestMapping("/Minio")
@Slf4j
public class MinioController {

    @Autowired
    private MinioService minioService;


    @Autowired
    private MinioUtil minioUtil;



    @PostMapping("/upload")
    @ApiOperation("minio上传")
    public CommonResult<List<String>> upload(@RequestParam(name = "multipartFile") MultipartFile[] multipartFile) {
        List<String> upload = minioUtil.upload(multipartFile);
        return CommonResult.ok(upload);
    }


    @ApiOperation(value = "minio下载测试")
    @GetMapping("/download")
    public ResponseEntity<byte[]> download(@RequestParam String fileName) {
        return minioUtil.download(fileName);
    }

    @ApiOperation(value = "minio创建桶")
    @PostMapping("/existBucket")
    public void existBucket(@RequestParam String bucketName) {
        minioUtil.existBucket(bucketName);
    }


}
